package com.epam.matchers;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.epam.resources.Resources;
import com.epam.text_elements.Word;

public class WordMatcher extends AbstractMatcher {
	private static final Pattern PATTERN=Pattern.compile(
			Resources.getString("WordMatcherPattern"));
	
	public WordMatcher(String src) {
		super(src);
	}
	
	public Word getNextWord() {
		String temp = super.nextStringElement(PATTERN);
		Word res;
		if (temp != null) {
			res = new Word(temp);
		} else {
			res = null;
		}
		return res;
	}
	
	public Word getNextWord(int nextWordPos) {
		String temp = super.nextStringElement(PATTERN, nextWordPos);
		Word res;
		if (temp != null) {
			res = new Word(temp);
		} else {
			res = null;
		}
		return res;
	}
	
	public int countWords() {
		Matcher matcher = PATTERN.matcher(this.src);
		int res=0;
		while (matcher.find()) {
			res++;
		}
		return res;
	}

}
